package org.irenty.domain;

import java.util.ArrayList;
import java.util.List;

import org.springframework.data.annotation.PersistenceConstructor;
import org.springframework.data.mongodb.core.mapping.DBRef;
import org.springframework.data.mongodb.core.mapping.Document;

public class League {

    private final String name;
    private final String country;
    @DBRef
    private List<Season> seasons;
    
    public League(String name, String country) {
        this.name = name;
        this.country = country;
    }
    
    @PersistenceConstructor
    public League(String name, String country, List<Season> seasons) {
        this.name = name;
        this.country = country;
        this.seasons = seasons;
    }

    public List<Season> getSeasons() {
        if (seasons == null) {
            seasons = new ArrayList<Season>();
        }
        return seasons;
    }

    public String getName() {
        return name;
    }

    public String getCountry() {
        return country;
    }

    @Override
    public String toString() {
        return "League [name=" + name + ", country=" + country + ", seasons=" + seasons + "]";
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((country == null) ? 0 : country.hashCode());
        result = prime * result + ((name == null) ? 0 : name.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        League other = (League) obj;
        if (country == null) {
            if (other.country != null)
                return false;
        } else if (!country.equals(other.country))
            return false;
        if (name == null) {
            if (other.name != null)
                return false;
        } else if (!name.equals(other.name))
            return false;
        return true;
    }
  }
